<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/common.jsp"%>

<title>商品评论</title>
</head>
<body>
		<%@ include file="../common/header.jsp"%>
		<div class="container">
			<div class="row">
					<div class="panel panel-default">
						<div class="panel-heading">
							评价商品
						</div>
						<div class="panel-body">
							<div class="media">
								<div class="media-left media-middle">
									<a href="${ctx}/product/${product.id}"> 
										<img src="${product.smallImage}" class="avatar">
									</a>
								</div>
								<div class="media-body media-middle">
									<a style="color: #333" class="title" href="${ctx}/product/${product.id}">
										<h5 class="media-heading">${product.name}</h5>
									</a>
								</div>
							</div>
						</div>
						<div class="panel-body">
							<form method="post">
								<div class="form-group">
									<label for="title">评价内容</label>
									<textarea name="content" id="content" rows="15"	class="form-control"></textarea>
								</div>
								<button type="button" onclick="commentSubmit()" class="btn btn-default">提交</button>
								<span id="error_message"></span>
							</form>
						</div>
					</div>
				</div>
			</div>
		<%@ include file="../common/footer.jsp"%>
	</div>
	<link rel="stylesheet" href="${ctx}/static/libs/editor/editor.css" />
	<script type="text/javascript" src="${ctx}/static/js/lodash.min.js"></script>
	<script type="text/javascript" src="${ctx}/static/libs/webuploader/webuploader.withoutimage.js"></script>
	<script type="text/javascript" src="${ctx}/static/libs/markdownit.js"></script>
	<script type="text/javascript" src="${ctx}/static/libs/editor/editor.js"></script>
	<script type="text/javascript" src="${ctx}/static/libs/editor/ext.js"></script>
	<script type="text/javascript">
		var editor = new Editor({
			element : $("#content")[0],
			status : []
		});
		editor.render();
	</script>
	<script type="text/javascript">
	function commentSubmit() {
		var errorMsg = $("#error_message");
		var content = editor.value();
		var orderNo = "${orderNo}";
		var productId = "${productId}";
		if (content.length == 0) {
			errorMsg.html("评价内容不能为空");
			return;
		}
		
		$.ajax({
			type : 'POST',
			url : ctx + '/order/addProductComment.do',
			data : {
				content : content,
				orderNo : orderNo,
				productId : productId
			},
			dataType : 'json',
			timeout : 30000,
			context : $('body'),
			success : function(data) {
				if (data.code == "ok") {
					//history.back();
					location.href = document.referrer;
				} else {
					errorMsg.html(data.msg);
				}
			},
			error : function(xhr, type) {
				errorMsg.html('提交失败!');
			}
		});
	}
	</script>
</body>
</html>